<?php
class ActivityAction extends AdminAction {

	#列表
	public function index() {
		$obj = M('PointDetail');
		$count = $obj->where($map)->count();
		import("@.ORG.Page");
		$page = new Page($count, 20);
		$show = $page->show();
		$list = $obj->where($map)->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
		foreach ($list as $key => $value) {
			unset($map);
			$map['id'] = $value['memberID'];
			$user = M('Member')->where($map)->find();
			$list[$key]['wxname'] = $user['wxname'];
			$list[$key]['wxface'] = $user['wxface'];
		}

		$this->assign('list', $list);
		$this->assign('page', $show);
		$this->display();
	}

	#删除
	public function del() {

		$id=I('post.selectedids');

		if($id==''){
			$state = "您没有选择任何信息！";
		}else{
			foreach ($id as $v) {
				$obj = M('PointDetail');
				$where['id'] = $v;
				$obj->where($where)->delete();
			}
			$state = 'SUCCESS';
	        $message = '删除成功';
	        $url = U('Activity/index');
		}
		echo $this->echo_json_str($state,$message,$url);
	}

	#兑奖
	public function ok() {
        $map['id']=I('get.id');
        $data['status']=1;
        $data['updateTime'] = time();
        M('PointDetail')->where($map)->save($data);
        redirect ($_SERVER['HTTP_REFERER']);
	}

	#设置
	public function setting() {
		if(isset($_POST['dosubmit'])) {
			$data['point'] = I('post.point');
			$data['shareNumber'] = I('post.shareNumber');
			$data['signNumber'] = I('post.signNumber');
			$data['name'] = serialize(I('post.name'));
			$data['value'] = serialize(I('post.value'));
			$data['probability'] = serialize(I('post.probability'));
			$obj = M('LotteryConfig');
			$obj->where('id=1')->save($data);
			$state = 'SUCCESS';
            $message = '操作成功';
            $url = U('Activity/setting');
            echo $this->echo_json_str($state,$message,$url);            
        }else{
			$list = M('LotteryConfig')->find();
			$list['name'] = unserialize($list['name']);
			$list['value'] = unserialize($list['value']);
			$list['probability'] = unserialize($list['probability']);
			$this->assign('list',$list);
			$this->display();
		}
	}



}
?>